﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PS3Packager
{
    public partial class OptionsForm : Form
    {
        public OptionsForm()
        {
            InitializeComponent();

            ftpEditor.UriStr = Properties.Settings.Default.PS3FtpUri;
            checkBoxAutomaticallyCopyToPS3.Checked = Properties.Settings.Default.PS3AutomaticallyCopy;
            textBoxLocalPkgFolder.Text = Properties.Settings.Default.LocalPkgFolder;
            checkBoxAutomaticallyCopyToLocalFolder.Checked = Properties.Settings.Default.LocalPkgAutomaticallyCopy;
            checkBoxMaintainFileAssociations.Checked = Properties.Settings.Default.MaintainP3PFileAssociations;

            checkBoxAutomaticallyCopyToPS3_CheckedChanged(null, null);
            checkBoxAutomaticallyCopyToLocalFolder_CheckedChanged(null, null);

            // Hide functionality not available yet. This was functionality added at an early stage before the PS3 Visual Studio add-in was created.
            groupBoxPS3.Visible = false;
            panel4.Visible = false;
            groupBoxLocal.Visible = false;
            panel5.Visible = false;

            this.ClientSize = new Size(this.ClientSize.Width, this.ClientSize.Height - groupBoxPS3.Height - panel4.Height - groupBoxLocal.Height - panel5.Height);
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.PS3FtpUri = ftpEditor.UriStr;
            Properties.Settings.Default.PS3AutomaticallyCopy = checkBoxAutomaticallyCopyToPS3.Checked;
            Properties.Settings.Default.LocalPkgFolder = textBoxLocalPkgFolder.Text;
            Properties.Settings.Default.LocalPkgAutomaticallyCopy = checkBoxAutomaticallyCopyToLocalFolder.Checked;
            Properties.Settings.Default.MaintainP3PFileAssociations = checkBoxMaintainFileAssociations.Checked;
            Properties.Settings.Default.Save();

            this.DialogResult = DialogResult.OK;
        }

        private void buttonBrowseLocalFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.ShowNewFolderButton = true;
            fbd.SelectedPath = textBoxLocalPkgFolder.Text;

            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBoxLocalPkgFolder.Text = fbd.SelectedPath;
            }
        }

        private void checkBoxAutomaticallyCopyToPS3_CheckedChanged(object sender, EventArgs e)
        {
            ftpEditor.Enabled = checkBoxAutomaticallyCopyToPS3.Checked;
        }

        private void checkBoxAutomaticallyCopyToLocalFolder_CheckedChanged(object sender, EventArgs e)
        {
            groupBoxLocalFolder.Enabled = checkBoxAutomaticallyCopyToLocalFolder.Checked;
        }
    }
}
